package util

import (
	"strings"

	"github.com/avct/uasurfer"
)

func ParseUa(uaString string) *uasurfer.UserAgent {
	ua := uasurfer.Parse(uaString)
	return ua
}

func ParseLdapIpPort(ldapAddr string) string {
	cleanAddr := strings.TrimSpace(ldapAddr)
	if strings.HasPrefix(cleanAddr, "ldap://") {
		return strings.TrimPrefix(ldapAddr, "ldap://")
	}

	if strings.HasPrefix(cleanAddr, "ldaps://") {
		return strings.TrimPrefix(ldapAddr, "ldaps://")
	}

	return cleanAddr
}

func LdapIsTls(ldapAddr string) bool {
	cleanAddr := strings.TrimSpace(ldapAddr)

	if strings.HasPrefix(cleanAddr, "ldaps://") {
		return true
	}

	return false
}
